@echo off
REM SimpleOS Windows 编译脚本

echo ==========================================
echo   Building SimpleOS 32-bit Operating System
echo ==========================================
echo.

REM 检查 NASM 是否安装
where nasm >nul 2>nul
if %ERRORLEVEL% NEQ 0 (
    echo [ERROR] NASM not found!
    echo Please install NASM from: https://www.nasm.us/
    echo Or use: winget install nasm
    pause
    exit /b 1
)

REM 编译引导扇区
echo [1/3] Compiling boot sector...
nasm -f bin boot.asm -o boot.bin
if %ERRORLEVEL% NEQ 0 (
    echo [ERROR] Boot sector compilation failed!
    pause
    exit /b 1
)
echo [OK] Boot sector compiled: boot.bin

REM 编译内核
echo [2/3] Compiling kernel...
nasm -f bin kernel.asm -o kernel.bin
if %ERRORLEVEL% NEQ 0 (
    echo [ERROR] Kernel compilation failed!
    pause
    exit /b 1
)
echo [OK] Kernel compiled: kernel.bin

REM 创建操作系统镜像
echo [3/3] Creating OS image...
copy /b boot.bin + kernel.bin os-image.bin >nul

REM 填充到合适大小（16384字节=32扇区，>= 1引导扇区 + 22个内核扇区）
fsutil file seteof os-image.bin 16384 >nul 2>nul

echo [OK] OS image created: os-image.bin
echo.
echo Build completed successfully!
echo.
dir boot.bin kernel.bin os-image.bin | findstr ".bin"
echo.
echo To run the OS, execute: run.bat
echo Or manually: qemu-system-i386 -drive format=raw,file=os-image.bin
echo.
pause

